package com.um.jdy.app.shop.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.app.shop.entity.dto.GoodsCollectionPageDTO;
import com.um.jdy.app.shop.entity.dto.GoodsIdDTO;
import com.um.jdy.app.shop.manager.GoodsCollectionManager;
import com.um.jdy.common.shop.entity.vo.GoodsVO;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.entity.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 收藏表
 *
 * @author lihuanyao
 * @company 广州优匠科技有限公司
 * @date 2020/9/29 11:50
 */
@Api(tags = "商品")
@RestController
@RequestMapping("/api/v1/goods/collection")
@SaCheckLogin
@Validated
public class GoodsCollectionController {

    @Autowired
    private GoodsCollectionManager goodsCollectionManager;

    /**
     * 查询收藏商品
     * @param dto
     * @return
     */
    @ApiOperation("查询收藏商品")
    @GetMapping("page")
    public Response<Page<GoodsVO>> getPage(@ModelAttribute GoodsCollectionPageDTO dto) {
        return Response.success(goodsCollectionManager.getPage(dto));
    }

    /**
     * 收藏/取消收藏
     *
     * @return
     */
    @ApiOperation("收藏/取消收藏")
    @PostMapping()
    public Response collection(@RequestBody GoodsIdDTO dto) {
        goodsCollectionManager.collection(dto);
        return Response.success();
    }


}
